<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体检结果</title>
</head>
<body>
<style type="text/css">
.resultBox .text-css{
	border: 0px;
    text-align: center;
    width: 80px;
    height: 24px;
    outline: none;
    color:black;
}
</style>
<script type="text/javascript">
$(function(){
	$('#recordTable').datagrid({
	    url:'ljw-examine-find',
 	    columns:[[
			{field:'examine_id',title:'体检号',width:60,halign:'center'},
			{field:'patient_name',title:'姓名',width:80,halign:'center'},
			{field:'patient_age',title:'年龄',width:45,halign:'center'},
			{field:'patient_sex',title:'性别',width:45,halign:'center'},
			{field:'examine_time',title:'登记时间',width:200,align:'center',
				formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}},
			{field:'examine_state',title:'缴费状态',width:100,align:'center',
				formatter: function(value,row,index){
					if(value==0){
						return "待缴费";
					}
					return "已缴费";
				}
			}
	    ]],
	    onClickRow:function(index, row){
	    	$(".resultBox .nameEx").val(row.patient_name);
	    	$(".resultBox .ageEx").val(row.patient_age);
	    	$(".resultBox .sexEx").val(row.patient_sex);
	    	$("#exTable").datagrid({
	    		url:"ljw-examine-findByeid?eid="+row.examine_id,
	    		onClickRow:function(index){//设置不可选中
	    			$(this).datagrid('unselectRow',index);
	    		}
	    	});
	    }
	});

	//结果录入按钮
	$("#resultBtn").click(function(){
		var rows = $("#exTable").datagrid("getRows");
		var a = -1; //需要获取焦点的行数
		for (var i = 0; i < rows.length ; i++) {
			var result =  rows[i].examine_record_result;
			if(typeof(result) == "undefined"){
				$("#exTable").datagrid("beginEdit", i);
				if(a == -1){
					a = i ;//只需获取第一行
					var editor = $('#exTable').datagrid('getEditor', {index:a,field:"examine_record_result"});//获取当前编辑器
				    $(editor.target).focus();//获取焦点
				}
			};
		}
	});
	
	//完成按钮
	$("#ok-exBtn").click(function(){
		var rows = $("#exTable").datagrid("getRows");
		var array = [];
		var opin = true;
		for (var i = 0; i < rows.length ; i++) {
			$("#exTable").datagrid('endEdit',i);//关闭编辑器
			var obj={};//创建对象
			obj.examine_record_id = rows[i].examine_record_id ;
			obj.examine_record_result = rows[i].examine_record_result ;
			if(typeof(obj.examine_record_result) == "undefined"||obj.examine_record_result==""){
				obj.examine_record_result = ""; 
				opin = false;
			}
			array.push(obj);
		}
		var json = JSON.stringify(array);//将对象转换为json
		$.post(
			"ljw-examine-result",
			{"json":json},
			function(data){
				$("#exTable").datagrid("reload");
				if(opin){
					$('#recordTable').datagrid("reload");
					$(".resultBox .nameEx").val("");
			    	$(".resultBox .ageEx").val("");
			    	$(".resultBox .sexEx").val("");
			    	$("#exTable").datagrid({//清空表格
			    		url:"ljw-examine-findByeid?eid="+0
			    	});
				}
			}
		);
	});
	
	//体检人搜索框
	$("#itmeSear").searchbox({
		searcher:function(value){
			$('#recordTable').datagrid({url:"ljw-examine-find?eid="+value});
		}
	});
	
});
</script>
<div style="margin: 5px auto;width: 1000px" class="resultBox">
	<fieldset style="float :left;border-radius: 5px;border: 1px solid darkseagreen;width: 600px;margin: 5px auto;">
		<legend>体检人列表</legend>
		<div style="padding: 5px;">
		 	<input id="itmeSear" class="easyui-searchbox" style="width:160px;height:28px;padding-left:5px;">
		</div>
		<table id="recordTable" style="height:380px;width:100%;"; class="easyui-datagrid" data-options="fitColumns:true,singleSelect:true">
	 			
		</table>
	</fieldset>
	
	<fieldset style="height: 450px;display: inline-block; padding: 0px 10px;margin: 5px 10px;border: 1px solid darkseagreen;border-radius: 5px;">
		<legend>体检信息</legend>
		<p>
			<span style="display: inline-block;margin-left: 30px;">
				姓名：<input class="text-css nameEx" disabled="disabled" style="width: 110px;">
			</span>
		</p>
		<p>
			<span style="display: inline-block;margin-left: 30px;">
				性别：<input class="text-css sexEx" style="width: 110px" disabled="disabled">
			</span>
		</p>
		<p>
			<span style="display: inline-block;margin-left: 30px;">
				年龄：<input class="text-css ageEx" style="width: 110px" disabled="disabled">
			</span>
		</p>
		<table id="exTable" style="height:240px;width:260px;"; class="easyui-datagrid" data-options="fitColumns:true,singleSelect:true">
	 		<thead>  
		        <tr>
		        	<th data-options="field:'examine_record_id',hidden:'true'">id</th>   
		        	<th data-options="field:'examine_item_name',width:160,halign:'center'">体检项目</th>   
		            <th data-options="field:'examine_record_result',width:250,halign:'center'"  editor="{type:'text', options:{required: true}}">体检结果</th>  
		        </tr>   
		    </thead>  
		</table>
		<p style="padding-left: 17px;">
			<a id="ok-exBtn" class="easyui-linkbutton" 
					style="padding:0 8px;float: right;margin-right: 40px;">完成</a>	
			<a id="resultBtn" class="easyui-linkbutton" 
					style="padding:0 8px;float: right;margin-right: 35px;">结果录入</a>
		</p>
	</fieldset>
</div>
</body>
</html>